/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007 Intel Corporation. All Rights Reserved.
//
//
*/

#ifndef __UMC_START_CODE_ARRAY_H
#define __UMC_START_CODE_ARRAY_H

#include "ippdefs.h"
#include "umc_structures.h"

namespace UMC
{

struct StartCodeDesc
{
    Ipp32u m_startCode;                                         // (Ipp32u) start code value
    Ipp32u m_startCodeOffset;                                   // (Ipp32u) start code's offset from the frame's beginning
};

class StartCodeArray
{
public:
    // Default constructor
    StartCodeArray(void);
    // Destructor
    virtual
    ~StartCodeArray(void);

    // Initialize the array
    virtual
    Status Init(void);

    // De-initialize the array
    virtual
    Status Close(void);

    // Get item from the array
    inline
    StartCodeDesc & operator [] (Ipp32s iIndex)
    {
        if (iIndex < m_iAllocated)
            return m_pStartCodes[iIndex];

        // we need to enlarge the array
        if (UMC_OK == Reallocate(align_value<Ipp32s> (iIndex + 1, 16)))
            return m_pStartCodes[iIndex];

        // error happened
        return m_pStartCodes[0];
    }

protected:
    // Reallocate array of start codes
    Status Reallocate(Ipp32s iNum);

    StartCodeDesc *m_pStartCodes;                               // (StartCodeDesc *) allocted array of start codes
    Ipp32s m_iAllocated;                                        // (Ipp32s) number of allocated items in the array
};

} // namespace UMC

#endif // __UMC_START_CODE_ARRAY_H
